#define _CRT_SECURE_NO_WARNINGS 

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

void swap(char* x, char* y, int sizeof1)
{ 
	for (int i = 0; i < sizeof1; ++i)
	{
		char tmp = *x ;
		*x = *y;
		*y = tmp;
		x++;
		y++;
	}

}
void _qsort(void* arr, int size, int sizeof1, int (*p)(const void*, const void*))
{
	if (arr != NULL)
	{
		for (int i = 0; i < size; ++i)
		{
			for (int j = 0; j < size - 1-i; ++j)
			{
				if (p((char*)arr + (sizeof1 * j), (char*)arr + (sizeof1 * (j)+1)) >= 1)
				{
					swap((char*)arr + (sizeof1 * j), (char*)arr + (sizeof1 * (j)+1), sizeof1);
				}
			}
		}
	}
}
int qsort_int(const void* x, const void* y)
{
	return *(int*)x - *(int*)y;
}
int qsort_char(const void* x, const void* y)
{
	return *(char*)x - *(char*)y;
}
typedef struct charr
{
	char arr[6];
}charr;
int qsort_charr(const void* x, const void* y)
{
	return strcmp(((charr*)x)->arr, ((charr*)y)->arr);
}
int qsort_float(const void* x, const void* y)
{
	float a = (*(float*)x);
	float b = (*(float*)y);

	if (a > b&& fabs(a-b)> 1e-6 )
		return 1;
	else if (a = b && fabs(a>b) > 1e-6 )
		return 0;
	else
		return -1;
}
int main()
{

	/*int arr[] = { 1,3,0,5,6,9,8,7,4,2 };
	int a = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, a, 4, qsort_int);
	for (int i = 0; i < a; i++)
	{
		printf("%d ", arr[i]);
	}*/

	/*char arr[] = { 'a','c', 'g', 'b', 'e', 'd', 'f' };
	int a = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, a, 1, qsort_char);
	for (int i = 0; i < a; i++)
	{
		printf("%c ", arr[i]);
	}*/
	charr arr[] = { "12345","abcde","bcdef","qwert","asdfg" };
	int a = sizeof(arr) / sizeof(arr[0]);
	int b = sizeof(arr[0]);
	qsort(arr, a, b, qsort_charr);
	for (int i = 0; i < a; i++)
	{
		printf("%s ", arr[i].arr);
	}

	/*float arr[] = { 0.0f,0.5f,0.7f,0.3f,0.2f,0.35f,0.66f };
		int a = sizeof(arr) / sizeof(arr[0]);
		int b = sizeof(arr[0]);
		qsort(arr, a, b, qsort_float);
		for (int i = 0; i < a; i++)
		{
			printf("%f ", arr[i]);
		}*/

}